package com.retailcloud.thirdpartyservice.service;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wudi
 * @date 2024/11/9
 * @comment
 */
@Service
public class WechatUserService {

    private final WxMaService wxMaService;

    @Autowired
    public WechatUserService(WxMaService wxMaService) {
        this.wxMaService = wxMaService;
    }

    public WxMaJscode2SessionResult getOpenId(String jsCode) throws Exception {
        WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(jsCode);
        return session;
    }

    public WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr) throws Exception {
        return wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, ivStr);
    }

    public WxMaPhoneNumberInfo getPhoneNumber(String encryptedData, String iv, String sessionKey) throws Exception {
        return wxMaService.getUserService().getPhoneNoInfo(encryptedData, iv, sessionKey);
    }
}
